package com.jx.gocomtask.webservice.service.impl;

import com.jx.gocomtask.webservice.DTO.GroupInfo;
import com.jx.gocomtask.webservice.DTO.UserSigleInfo;
import com.jx.gocomtask.webservice.service.GroupService;
import com.jx.gocomtask.webservice.service.SystemSuperApp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import phoenics.common.BaseData.BaseErrorCode;
import phoenics.common.exception.NotFoundException;

import javax.annotation.Resource;

/**
 * Created by LWD on 2017/8/7.
 */
@Service
public class GroupServiceImp implements GroupService {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(GroupServiceImp.class);
    @Resource(name="apiurl")
    String gocomeApiUrl;
    @Resource(name="defaultGroupAppId")
    String defaultGroupAppId;
    @Autowired
    RestTemplate restTemplate;
    @Resource
    private SystemSuperApp systemSuperApp;
    @Override
    public GroupInfo findByGuId(String guid) {
        String url=gocomeApiUrl + "groupapp/group/info?"+systemSuperApp.appid_token(defaultGroupAppId);
        url+="&groupid="+guid;
        GroupInfo groupInfo= restTemplate.getForObject(url, GroupInfo.class);
        if(null == groupInfo)
            throw new NotFoundException(BaseErrorCode.GROUP_BAD_NOT_FOUND, BaseErrorCode.GROUP_BAD_NOT_FOUND_MSG);
        return groupInfo;
    }
}
